package com.jspgou.cms.manager.impl;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.jspgou.cms.dao.FullGiveDao;
import com.jspgou.cms.entity.FullGive;
import com.jspgou.cms.entity.Store;
import com.jspgou.cms.manager.FullGiveMng;
import com.jspgou.common.hibernate3.Updater;
import com.jspgou.common.page.Pagination;
import com.jspgou.core.manager.WebsiteMng;

@Service
@Transactional
public class FullGiveMngImpl implements FullGiveMng {
	@Transactional(readOnly = true)
	public Pagination getPage(int pageNo, int pageSize) {
		Pagination page = dao.getPage(pageNo, pageSize);
		return page;
	}
	
	public Pagination getPage(Long websiteId,Long storeId,Boolean disable,Boolean deleted,int pageNo, int pageSize){
		Pagination page=dao.getPage(websiteId, storeId, disable, deleted, pageNo, pageSize);
		return page;
	}
	
	public List<FullGive> getList(Long websiteId,Long storeId,Boolean disable,Boolean deleted){
		List<FullGive> list=dao.getList(websiteId, storeId, disable, deleted);
		return list;
	}

	@Transactional(readOnly = true)
	public FullGive findById(Long id) {
		FullGive entity = dao.findById(id);
		return entity;
	}

	public FullGive save(FullGive bean) {
		dao.save(bean);
		return bean;
	}
	
	public FullGive save(Long websiteId,Store store,FullGive bean) {
		bean.setWebsite(websiteMng.findById(websiteId));
		bean.setStore(store);
		dao.save(bean);
		return bean;
	}

	public FullGive update(FullGive bean) {
		Updater<FullGive> updater = new Updater<FullGive>(bean);
		FullGive entity = dao.updateByUpdater(updater);
		return entity;
	}

	public FullGive deleteById(Long id) {
		FullGive bean = dao.deleteById(id);
		return bean;
	}
	
	public FullGive[] deleteByIds(Long[] ids) {
		FullGive[] beans = new FullGive[ids.length];
		for (int i = 0,len = ids.length; i < len; i++) {
			beans[i] = deleteById(ids[i]);
		}
		return beans;
	}

	private FullGiveDao dao;
	@Autowired
	private WebsiteMng websiteMng;

	@Autowired
	public void setDao(FullGiveDao dao) {
		this.dao = dao;
	}
}